package jmine.tec.web.wicket.component.breadcrumb;

import images.ImageResources;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.panel.Panel;

import bancosys.tec.exception.LocalizedMessageHolder;

/**
 * Painel wicket para breadcrumb.
 * 
 * @author Gallardo
 */
public class BreadcrumbPanel extends Panel {

    public static final String BREAD_CRUMB_SEPARATOR = " - ";

    /**
     * Construtor.
     * 
     * @param id o id wicket do panel.
     * @param path o path da tela.
     * @param helpMessageHolder {@link LocalizedMessageHolder} do texto de ajuda
     */
    public BreadcrumbPanel(String id, String[] path, LocalizedMessageHolder helpMessageHolder) {
        super(id);
        String breadCrumb = "";
        boolean visible = false;
        if (path != null && path.length > 0) {
            visible = true;
            breadCrumb = StringUtils.join(path, BREAD_CRUMB_SEPARATOR);
        }
        this.add(new Image("seta", new ResourceReference(ImageResources.class, "f_hum.gif")).setVisible(visible));

        String message = helpMessageHolder != null ? helpMessageHolder.getMessage() : null;
        if (!StringUtils.isEmpty(message)) {
            this.add(new Image("help", new ResourceReference(ImageResources.class, "help.png")).setVisible(visible));
            this.add(new Label("helpText", message).setEscapeModelStrings(false));
        } else {
            this.add(new Image("help", new ResourceReference(ImageResources.class, "help.png")).setVisible(false));
            this.add(new Label("helpText", ""));
        }

        this.add(new Label("breadcrumb", breadCrumb));
    }
}
